﻿<cfscript>
/** 
* @hint "taskManager - Course Task"
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.senate.courseTaskListener" 
	output=false 
	depends="senateMathAdvice, taskPropertyAdvice, choosePropertyAdvice, datetimeAdvice, sessionAdvice, tagSettingHelper, sequenceProgramTask, sequenceCommonTask, sequenceOpenTask, sequenceSportTask,
	sequenceTeacherTimeTable, sequenceTaskAdjust, sequenceTaskTimeTable, sequenceClassroomTimeTable, logFactory"
	{
	
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 
	
	
	/**
	* @hint "管理岗位执行临时更换教室"
	* 
	* @event "MachII Event Object"
	*/	
	public void function changeTaskPlaceTemporality( required MachII.framework.Event event ) output=false {
		
		var sequenceClassroomTimeTable = getsequenceClassroomTimeTable();
		var sequencetaskAdjust = getsequencetaskAdjust();
		
		var courseId = event.getArg("CourseID");
		var teacherId = event.getArg("TeacherID");
		var roomId = event.getArg("ClassroomID");
		var adminId = getsessionAdvice().getAutherUserID();
		
		var termId = event.getArg("TermID");
		var taskId = event.getArg("TaskID");
		var taskType = event.getArg("TaskType");
		
		var targetWeek = event.getArg("WeekID");
		var targetTimeCell = event.getArg("TaskTime");
		
		var timeStamp = getdatetimeAdvice().getCurrentDatetimeString();
		var mathAdvice = getsenateMathAdvice();
		
		var weekDay = event.getArg("wkday");
		var lectureId = event.getArg("lec");
		var cells = event.getArg("n");
		
		var cellStart = mathAdvice.convertLectureIdxToCellStart(lectureId);
		var cellEnd = cellStart + cells -1;
		
		var sql = "";
		var queryObj = "";

		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 加载指定教学班 */
			switch(taskType){
				case "C":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_common_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
	
				case "P":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
				
				case "R":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_reopen_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
				
				case "T":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_sport_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
			}
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			var rs_taskClassObj = queryObj.execute( sql=sql ).getResult();
			
			/* 目标教室 */
			sql = "SELECT classroom FROM t_classroom WHERE cr_id = :classroomID ";
		
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="classroomID", value=roomId, cfsqltype="cf_sql_char" );
			var rs_classroom = queryObj.execute( sql=sql ).getResult();
			
			/* 按照停课逻辑, 处理上课教室时间占用 */
			sql = "SELECT 
						t_clsroom_forcourse.crtime_id, t_clsroom_timetable.widx, t_clsroom_forcourse.tidx 
					FROM 
					   t_clsroom_forcourse 
					   INNER JOIN t_clsroom_timetable ON t_clsroom_timetable.crtime_id = t_clsroom_forcourse.crtime_id 
					WHERE 
						t_clsroom_forcourse.task_id = :taskId 
						AND 
						t_clsroom_forcourse.tasktime = :targetTimeCell 
						AND 
						SUBSTR(t_clsroom_timetable.widx, " &targetWeek& ", 1) = '1' ";
						
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="targetTimeCell", value=targetTimeCell, cfsqltype="cf_sql_varchar" );
			var rs_roomObj = queryObj.execute( sql=sql ).getResult();
			
		
			for ( var j=1; j LTE rs_roomObj.recordCount; j++){
				
				var weekIdx = rs_roomObj["widx"][j];
				var weekArray = [];
				
				/* 将周次序列字符串转换为数组 */
				for ( var i=1; i lte 25; i++ ) { 
					arrayAppend(weekArray, mid(weekIdx, i, 1));
				}
				
				/* 指定周次是否使用设置为 0 即停课一周 */
				arraySet( weekArray, targetWeek, targetWeek, 0 );
				
				sql = "UPDATE t_clsroom_timetable 
						set widx = :weekIndex 
						WHERE crtime_id = :crtimeId ";
						
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="crtimeId", value=rs_roomObj["crtime_id"][j], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="weekIndex", value=arrayToList( weekArray, "" ), cfsqltype="cf_sql_char" );
				queryObj.execute( sql=sql );
	
			}
			
			var taskWeek = numberFormat( targetWeek, "0_" ) & "-" & numberFormat( targetWeek, "0_" );
			var weekIdx = mathAdvice.convertWeekIdx( taskWeek );
			var timeIdx = "001";
			
			/* 如果指定时间, 指定周次, 有使用教室, 则教学班排课序列号应当保持一致 */
			if ( rs_roomObj.recordCount eq 1 ) {
				timeIdx = rs_roomObj.tidx;
			}

			/* 教室时间占用 */
			sequenceClassroomTimeTable.setTermID(rs_taskClassObj.term_id);
			sequenceClassroomTimeTable.setClassroomID(roomId);
			var useIdx = sequenceClassroomTimeTable.getIDX();
			
			sequenceClassroomTimeTable.setIndex(useIdx);
			var useId = sequenceClassroomTimeTable.getID();
			
			sql = "INSERT INTO t_clsroom_timetable(
										crtime_id,
										term_id,
										cr_id,
										ut_id,
										uidx,
										widx,
										wdidx,
										cellidx,
										cellrelay
									)VALUES(
										:classRoomTimeId, 
										:termId, 
										:classroomId, 
										:usageType,
										:userIndex, 
										:weekIndex, 
										:weekDay, 
										:cellStart, 
										:cellLength 
									)";
								
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="classRoomTimeId", value=useId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="termId", value=rs_taskClassObj.term_id, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="classroomId", value=roomId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="usageType", value="1", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="userIndex", value=useIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekIndex", value=weekIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekDay", value=weekDay, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="cellStart", value=cellStart, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="cellLength", value=cells, cfsqltype="cf_sql_integer" );
			queryObj.execute( sql=sql );
			
			sql = "INSERT INTO t_clsroom_forcourse(
									crtime_id,
									task_id,
									tidx,
									task_type,
									taskclsroom,
									tasktime,
									task_week,
									task_course
								)VALUES(
									:classRoomTimeId,
									:taskId, 
									:taskTimeIndex, 
									:taskType, 
									:taskClassRoom, 
									:taskClassTime, 
									:taskWeek, 
									:taskCourse 
								)";
								
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="classRoomTimeId", value=useId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskTimeIndex", value=timeIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskType", value=taskType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskClassRoom", value=rs_classroom.classroom, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskClassTime", value=weekDay &"@"& lectureId & "-" & cells, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskCourse", value=rs_taskClassObj.course_name, cfsqltype="cf_sql_varchar" );

			queryObj.execute( sql=sql );
			
			
			/* 检查补单是否有重复记录 */
			sql = "SELECT sign_id 
					FROM t_task_adjust 
					WHERE 
						change_type = '30' 
						AND 
						task_id = :taskId 
						AND 
						change_desc = :changeDesc ";
						
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="changeDesc", value=event.getArg("ChangeDescription"), cfsqltype="cf_sql_varchar" );
			var rs_docObj = queryObj.execute( sql=sql ).getResult();
			
			if ( rs_docObj.recordCount EQ 0 ) {
				
				var docId = sequencetaskAdjust.getNextID();
				
				/* 生成调停课记录 */
				sql = "INSERT INTO t_task_adjust(
										sign_id,
										term_id,
										cid,
										sign_user_id,
										admin_user_id,
										change_type,
										task_id,
										task_type,
										date_created,
										date_review,
										change_reason,
										change_meta,
										change_desc,
										sign_status
									)VALUES(
										:signId, 
										:termId, 
										:courseId, 
										:signUserId, 
										:adminUserId, 
										:changeType,
										:taskId, 
										:taskType, 
										:dateCreated, 
										:dateReview, 
										:changeReason, 
										:changeMeta, 
										:changeDesc, 
										:signStatus  
									)";
									
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="signId", value=docId, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="termId", value=rs_taskClassObj.term_id, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_taskClassObj.cid, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="signUserId", value=rs_taskClassObj.tch_id, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="adminUserId", value=adminId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="changeType", value="30", cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskType", value=taskType, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="dateCreated", value=timeStamp, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="dateReview", value=timeStamp, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="changeReason", value=event.getArg("ChangeReason", "40"), cfsqltype="cf_sql_char" );
				queryObj.addParam( name="changeMeta", value=event.getArg("ChangeTarget"), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="changeDesc", value=event.getArg("ChangeDescription"), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="signStatus", value="P", cfsqltype="cf_sql_char" );
				queryObj.execute( sql=sql );
				
			}
			else {
				var docId = rs_docObj.sign_id;
			}
			

			var passArgs = structNew();
			
			structInsert( passArgs, "DOCID", docId );
			
			structInsert( passArgs, "TSK", taskId );
			structInsert( passArgs, "TT", taskType );
			structInsert( passArgs, "W", targetWeek );
			structInsert( passArgs, "TSKTIME", targetTimeCell );
			structInsert( passArgs, "TID", termId );
			
			event.setArgs( passArgs );
			
		}
		
	}


	/**
	* @hint "管理岗位执行临时性补课"
	* 
	* @event "MachII Event Object"
	*/	
	public void function appendTaskTemporality( required MachII.framework.Event event ) output=false {
		
		var sequenceTaskTimeTable = getsequenceTaskTimeTable();
		var sequenceClassroomTimeTable = getsequenceClassroomTimeTable();
		var sequenceTeacherTimeTable = getsequenceTeacherTimeTable();
		var sequencetaskAdjust = getsequencetaskAdjust();
		
		var courseId = event.getArg("CourseID");
		var teacherId = event.getArg("TeacherID");
		var roomId = event.getArg("ClassroomID");
		var adminId = getsessionAdvice().getAutherUserID();
		
		var termId = event.getArg("TermID");
		var taskId = event.getArg("TaskID");
		var taskType = event.getArg("TaskType");
		
		var targetWeek = event.getArg("WeekID");
		var targetTimeCell = event.getArg("TaskTime");
		
		var timeStamp = getdatetimeAdvice().getCurrentDatetimeString();
		var mathAdvice = getsenateMathAdvice();
		
		var weekDay = event.getArg("wkday");
		var lectureId = event.getArg("lec");
		var cells = event.getArg("n");
		
		var cellStart = mathAdvice.convertLectureIdxToCellStart(lectureId);
		var cellEnd = cellStart + cells -1;
		
		var taskWeek = numberFormat( targetWeek, "0_" ) & "-" & numberFormat( targetWeek, "0_" );
		var weekIdx = mathAdvice.convertWeekIdx( taskWeek );
		
		var sql = "";
		var queryObj = ""; 
		
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 载入排课任务 */
			sql = "SELECT period_done FROM t_task_arrange WHERE task_id = :taskId ";
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			var rs_taskArrange = queryObj.execute( sql=sql ).getResult();
			
			/* 加载指定教学班 */
			switch(taskType){
				case "C":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_common_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
	
				case "P":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
				
				case "R":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_reopen_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
				
				case "T":
					sql = "SELECT a.term_id, a.cid, a.tch_id, t_course.course_name 
							FROM t_sport_task a
							INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE a.tsk_id = :taskId ";
					break;
			}
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			var rs_taskClassObj = queryObj.execute( sql=sql ).getResult();
			
			/* 目标教室 */
			sql = "SELECT classroom FROM t_classroom WHERE cr_id = :classroomID ";
		
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="classroomID", value=roomId, cfsqltype="cf_sql_char" );
			var rs_classroom = queryObj.execute( sql=sql ).getResult();
			
			/* 教学班时间占用 */
			sequenceTaskTimeTable.setTaskID(taskId);
			var timeIdx = sequenceTaskTimeTable.getTimeIDX();
			
			sequenceTaskTimeTable.setTimeIndex(timeIdx);
			var timeId = sequenceTaskTimeTable.getID();
			
			sql = "INSERT INTO t_task_timetable(
									tasktime_id,
									task_id,
									tidx,
									widx,
									wdidx,
									cellidx,
									cellrelay,
									taskclsroom,
									tasktime,
									task_week 
								)VALUES(
									:tasktimeId, 
									:taskId, 
									:timeIndex, 
									:weekIndex, 
									:weekDay, 
									:cellStart, 
									:cellLength, 
									:taskclassRoom, 
									:taskclassTime, 
									:taskWeek 
								)";
								
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="tasktimeId", value=timeId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="timeIndex", value=timeIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekIndex", value=weekIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekDay", value=weekDay, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="cellStart", value=cellStart, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="cellLength", value=cells, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskclassRoom", value=rs_classroom.classroom, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskclassTime", value=weekDay &"@"& lectureId & "-" & cells, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
			
			/* 教室时间占用 */
			sequenceClassroomTimeTable.setTermID(rs_taskClassObj.term_id);
			sequenceClassroomTimeTable.setClassroomID(roomId);
			var useIdx = sequenceClassroomTimeTable.getIDX();
			
			sequenceClassroomTimeTable.setIndex(useIdx);
			var useId = sequenceClassroomTimeTable.getID();
			
			sql = "INSERT INTO t_clsroom_timetable(
										crtime_id,
										term_id,
										cr_id,
										ut_id,
										uidx,
										widx,
										wdidx,
										cellidx,
										cellrelay
									)VALUES(
										:classRoomTimeId, 
										:termId, 
										:classroomId, 
										:usageType,
										:userIndex, 
										:weekIndex, 
										:weekDay, 
										:cellStart, 
										:cellLength 
									)";
								
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="classRoomTimeId", value=useId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="termId", value=rs_taskClassObj.term_id, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="classroomId", value=roomId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="usageType", value="1", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="userIndex", value=useIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekIndex", value=weekIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekDay", value=weekDay, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="cellStart", value=cellStart, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="cellLength", value=cells, cfsqltype="cf_sql_integer" );
			queryObj.execute( sql=sql );
			
			sql = "INSERT INTO t_clsroom_forcourse(
									crtime_id,
									task_id,
									tidx,
									task_type,
									taskclsroom,
									tasktime,
									task_week,
									task_course
								)VALUES(
									:classRoomTimeId,
									:taskId, 
									:taskTimeIndex, 
									:taskType, 
									:taskClassRoom, 
									:taskClassTime, 
									:taskWeek, 
									:taskCourse 
								)";
								
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="classRoomTimeId", value=useId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskTimeIndex", value=timeIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskType", value=taskType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskClassRoom", value=rs_classroom.classroom, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskClassTime", value=weekDay &"@"& lectureId & "-" & cells, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskCourse", value=rs_taskClassObj.course_name, cfsqltype="cf_sql_varchar" );

			queryObj.execute( sql=sql );
			
			
			/* 教师时间占用 */
			sequenceTeacherTimeTable.setTermID(rs_taskClassObj.term_id);
			sequenceTeacherTimeTable.setTeacherID(rs_taskClassObj.tch_id);
			var tchTimeIdx = sequenceTeacherTimeTable.getTimeIDX();
			
			sequenceTeacherTimeTable.setTimeIndex(tchTimeIdx);
			var tchTimeId = sequenceTeacherTimeTable.getID();
			
			
			sql = "INSERT INTO t_teacher_timetable (
									teachertime_id,
									term_id,
									tch_id,
									cid,
									tidx,
									widx,
									wdidx,
									cellidx,
									cellrelay,
									taskclsroom,
									tasktime,
									task_id,
									task_type,
									task_week
								)VALUES(
									:teachertimeId, 
									:termId, 
									:teacherId, 
									:courseId, 
									:timeIndex, 
									:weekIndex, 
									:weekDay, 
									:cellStart, 
									:cellLength, 
									:taskClassRoom, 
									:taskTime, 
									:taskId, 
									:taskType, 
									:taskWeek 
								)";
								
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="teachertimeId", value=tchTimeId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="termId", value=rs_taskClassObj.term_id, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="teacherId", value=rs_taskClassObj.tch_id, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="courseId", value=rs_taskClassObj.cid, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="timeIndex", value=tchTimeIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekIndex", value=weekIdx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="weekDay", value=weekDay, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="cellStart", value=cellStart, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="cellLength", value=cells, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskClassRoom", value=rs_taskClassObj.course_name, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskTime", value=weekDay &"@"& lectureId & "-" & cells, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskType", value=taskType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
			
			
			/* 累计已排周学时 */
			var periodDone = rs_taskArrange.period_done + cells;
			
			sql = "UPDATE t_task_arrange SET period_done = :periodDone WHERE task_id = :taskId "; 
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="periodDone", value=periodDone, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			
			/* 检查补单是否有重复记录 */
			sql = "SELECT sign_id 
					FROM t_task_adjust 
					WHERE 
						change_type = '12' 
						AND 
						task_id = :taskId 
						AND 
						change_desc = :changeDesc ";
						
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="changeDesc", value=event.getArg("ChangeDescription"), cfsqltype="cf_sql_varchar" );
			var rs_docObj = queryObj.execute( sql=sql ).getResult();
			
			if ( rs_docObj.recordCount EQ 0 ) {
				
				var docId = sequencetaskAdjust.getNextID();

				/* 生成调停课记录 */
				sql = "INSERT INTO t_task_adjust(
										sign_id,
										term_id,
										cid,
										sign_user_id,
										admin_user_id,
										change_type,
										task_id,
										task_type,
										date_created,
										date_review,
										change_reason,
										change_meta,
										change_desc,
										sign_status
									)VALUES(
										:signId, 
										:termId, 
										:courseId, 
										:signUserId, 
										:adminUserId, 
										:changeType,
										:taskId, 
										:taskType, 
										:dateCreated, 
										:dateReview, 
										:changeReason, 
										:changeMeta, 
										:changeDesc, 
										:signStatus  
									)";
									
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="signId", value=docId, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="termId", value=rs_taskClassObj.term_id, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_taskClassObj.cid, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="signUserId", value=rs_taskClassObj.tch_id, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="adminUserId", value=adminId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="changeType", value="12", cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskType", value=taskType, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="dateCreated", value=timeStamp, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="dateReview", value=timeStamp, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="changeReason", value=event.getArg("ChangeReason", "30"), cfsqltype="cf_sql_char" );
				queryObj.addParam( name="changeMeta", value=event.getArg("ChangeTarget"), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="changeDesc", value=event.getArg("ChangeDescription"), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="signStatus", value="P", cfsqltype="cf_sql_char" );
				queryObj.execute( sql=sql );
				
			}
			else {
				var docId = rs_docObj.sign_id;
			}
			

			var passArgs = structNew();
			
			structInsert( passArgs, "DOCID", docId );
			
			structInsert( passArgs, "TSK", taskId );
			structInsert( passArgs, "TT", taskType );
			structInsert( passArgs, "W", targetWeek );
			structInsert( passArgs, "TSKTIME", targetTimeCell );
			structInsert( passArgs, "TID", termId );
			
			event.setArgs( passArgs );
	
		}
		
	}
	
	
	/**
	* @hint "管理岗位执行临时性停课"
	* 
	* @event "MachII Event Object"
	*/	
	public void function stopTaskTemporality( required MachII.framework.Event event ) output=false {
		
		var sequencetaskAdjust = getsequencetaskAdjust();
		
		var courseId = event.getArg("CourseID");
		var teacherId = event.getArg("TeacherID");
		var adminId = getsessionAdvice().getAutherUserID();
		
		var termId = event.getArg("TermID");
		var taskId = event.getArg("TaskID");
		var taskType = event.getArg("TaskType");
		
		var targetWeek = event.getArg("WeekID");
		var targetTimeCell = event.getArg("TaskTime");
		
		var timeStamp = getdatetimeAdvice().getCurrentDatetimeString();
		
		var sql = "";
		var queryObj = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 加载指定教学班 */
			switch(taskType){
				case "C":
					sql = "SELECT term_id, cid, tch_id 
							FROM t_common_task 
							WHERE tsk_id = :taskId ";
					break;
	
				case "P":
					sql = "SELECT term_id, cid, tch_id 
							FROM t_task 
							WHERE tsk_id = :taskId ";
					break;
				
				case "R":
					sql = "SELECT term_id, cid, tch_id 
							FROM t_reopen_task 
							WHERE tsk_id = :taskId ";
					break;
				
				case "T":
					sql = "SELECT term_id, cid, tch_id 
							FROM t_sport_task  
							WHERE tsk_id = :taskId ";
					break;
			}
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			var rs_taskClassObj = queryObj.execute( sql=sql ).getResult();
				
			/* 教学班时间占用 */
			sql = "SELECT 
						tasktime_id, widx 
					FROM 
						t_task_timetable 
					WHERE 
						task_id = :taskId 
						AND 
						tasktime = :targetTimeCell 
						AND 
						SUBSTR(widx, " &targetWeek& ", 1) = '1' ";
						
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="targetTimeCell", value=targetTimeCell, cfsqltype="cf_sql_varchar" );
			var rs_taskObj = queryObj.execute( sql=sql ).getResult();
		
			for ( var m=1; m LTE rs_taskObj.recordCount; m++){
				
				var weekIdx = rs_taskObj["widx"][m];
				var weekArray = [];
				
				/* 将周次序列字符串转换为数组 */
				for ( var i=1; i lte 25; i++ ) { 
					arrayAppend(weekArray, mid(weekIdx, i, 1));
				}
				
				/* 指定周次是否使用设置为 0 即停课一周 */
				arraySet( weekArray, targetWeek, targetWeek, 0 );
				
				sql = "UPDATE t_task_timetable 
						set widx = :weekIndex 
						WHERE tasktime_id = :taskTimeId ";
						
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskTimeId", value=rs_taskObj["tasktime_id"][m], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="weekIndex", value=arrayToList( weekArray, "" ), cfsqltype="cf_sql_char" );
				queryObj.execute( sql=sql );
			
			}											

			/* 教室时间占用 */
			sql = "SELECT 
						t_clsroom_forcourse.crtime_id, t_clsroom_timetable.widx
					FROM 
					   t_clsroom_forcourse 
					   INNER JOIN t_clsroom_timetable ON t_clsroom_timetable.crtime_id = t_clsroom_forcourse.crtime_id 
					WHERE 
						t_clsroom_forcourse.task_id = :taskId 
						AND 
						t_clsroom_forcourse.tasktime = :targetTimeCell 
						AND 
						SUBSTR(t_clsroom_timetable.widx, " &targetWeek& ", 1) = '1' ";
						
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="targetTimeCell", value=targetTimeCell, cfsqltype="cf_sql_varchar" );
			var rs_roomObj = queryObj.execute( sql=sql ).getResult();
		
			for ( var j=1; j LTE rs_roomObj.recordCount; j++){	
			
				var weekIdx = rs_roomObj["widx"][j];
				var weekArray = [];
				
				/* 将周次序列字符串转换为数组 */
				for ( var i=1; i lte 25; i++ ) { 
					arrayAppend(weekArray, mid(weekIdx, i, 1));
				}
				
				/* 指定周次是否使用设置为 0 即停课一周 */
				arraySet( weekArray, targetWeek, targetWeek, 0 );
				
				sql = "UPDATE t_clsroom_timetable 
						set widx = :weekIndex 
						WHERE crtime_id = :crtimeId ";
						
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="crtimeId", value=rs_roomObj["crtime_id"][j], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="weekIndex", value=arrayToList( weekArray, "" ), cfsqltype="cf_sql_char" );
				queryObj.execute( sql=sql );
						
			}

			/* 教师时间占用 */
			sql = "SELECT 
						teachertime_id, widx 
					FROM 
					   t_teacher_timetable 
					WHERE 
						task_id = :taskId 
						AND 
						tasktime = :targetTimeCell 
						AND 
						SUBSTR(widx, " &targetWeek& ", 1) = '1' ";
						
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="targetTimeCell", value=targetTimeCell, cfsqltype="cf_sql_varchar" );
			var rs_teacherObj = queryObj.execute( sql=sql ).getResult();
			
			for ( var x=1; x LTE rs_teacherObj.recordCount; x++){
			
				var weekIdx = rs_teacherObj["widx"][x];
				var weekArray = [];
				
				/* 将周次序列字符串转换为数组 */
				for ( var i=1; i lte 25; i++ ) { 
					arrayAppend(weekArray, mid(weekIdx, i, 1));
				}
				
				/* 指定周次是否使用设置为 0 即停课一周 */
				arraySet( weekArray, targetWeek, targetWeek, 0 );
				
				sql = "UPDATE t_teacher_timetable 
						set widx = :weekIndex 
						WHERE teachertime_id = :teacherTimeId ";
						
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="teacherTimeId", value=rs_teacherObj["teachertime_id"][x], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="weekIndex", value=arrayToList( weekArray, "" ), cfsqltype="cf_sql_char" );
				queryObj.execute( sql=sql );
				
			}

			/* 检查停课单是否有重复记录 */
			sql = "SELECT 
						sign_id 
					FROM 
						t_task_adjust 
					WHERE 
						change_type = '11' 
						AND 
						task_id = :taskId 
						AND 
						change_desc = :changeDesc ";
						
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="changeDesc", value=event.getArg("ChangeDescription"), cfsqltype="cf_sql_varchar" );
			var rs_docObj = queryObj.execute( sql=sql ).getResult();
			
			if ( rs_docObj.recordCount EQ 0 ) {
				
				var docId = sequencetaskAdjust.getNextID();

				/* 生成调停课记录 */
				sql = "INSERT INTO t_task_adjust(
										sign_id,
										term_id,
										cid,
										sign_user_id,
										admin_user_id,
										change_type,
										task_id,
										task_type,
										date_created,
										date_review,
										change_reason,
										change_meta,
										change_desc,
										sign_status
									)VALUES(
										:signId, 
										:termId, 
										:courseId, 
										:signUserId, 
										:adminUserId, 
										:changeType,
										:taskId, 
										:taskType, 
										:dateCreated, 
										:dateReview, 
										:changeReason, 
										:changeMeta, 
										:changeDesc, 
										:signStatus  
									)";
									
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="signId", value=docId, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="termId", value=rs_taskClassObj.term_id, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_taskClassObj.cid, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="signUserId", value=rs_taskClassObj.tch_id, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="adminUserId", value=adminId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="changeType", value="11", cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskType", value=taskType, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="dateCreated", value=timeStamp, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="dateReview", value=timeStamp, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="changeReason", value=event.getArg("ChangeReason", "21"), cfsqltype="cf_sql_char" );
				queryObj.addParam( name="changeMeta", value=event.getArg("ChangeTarget"), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="changeDesc", value=event.getArg("ChangeDescription"), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="signStatus", value="P", cfsqltype="cf_sql_char" );
				queryObj.execute( sql=sql );
	
			}
			else {
				var docId = rs_docObj.sign_id;
			}
			

			var passArgs = structNew();
			
			structInsert( passArgs, "DOCID", docId );
			
			structInsert( passArgs, "TSK", taskId );
			structInsert( passArgs, "TT", taskType );
			structInsert( passArgs, "W", targetWeek );
			structInsert( passArgs, "TSKTIME", targetTimeCell );
			structInsert( passArgs, "TID", termId );
			
			event.setArgs( passArgs );

		}

	}
	
	
	/**
	* @hint "刷新开课部门教学任务已选人数"
	* 
	* @event "MachII Event Object"
	*/	
	public void function flushInstituteTask( required MachII.framework.Event event ) output=false {
		
		var setting = gettagSettingHelper();
		setting.setTimeout(60);
		
		var termId = event.getArg("TermID", event.getArg("TID"));
		var depId = event.getArg("DepID");
		
		var errorTask = [];
		
		var sql = "";
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 刷新课程教学班已选人数 */
			sql = "SELECT 
						t_student_course.task_type, 
						t_student_course.task_id, 
						COUNT(*) countCourse 
					FROM 
						t_student_course 
						INNER JOIN t_course ON t_course.cid = t_student_course.cid 
					WHERE 
						t_student_course.term_id = :termId 
						AND 
						t_course.institute_id = :depId 
					GROUP BY 
						t_student_course.task_type, 
						t_student_course.task_id ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="depId", value=depId, cfsqltype="cf_sql_varchar" );
			rs_courseChoosers = queryObj.execute( sql=sql ).getResult();
			
			for(var row=1; row LTE rs_courseChoosers.recordCount; row++){	
			
				switch(rs_courseChoosers["task_type"][row]){
					case 'C':
						sql = "SELECT 1
							   FROM t_common_task  
							   WHERE tsk_id = :taskId ";
						break;
					case 'P':
						sql = "SELECT 1 
							   FROM t_task 
							   WHERE tsk_id = :taskId ";
						break;
					case 'R':
						sql = "SELECT 1 
							   FROM t_reopen_task 
							   WHERE tsk_id = :taskId ";
						break;
					case 'T':
						sql = "SELECT 1 
							   FROM t_sport_task 
							   WHERE tsk_id = :taskId ";
						break;
				}
				queryObj = new Query(datasource = application.dnsMaster);
				queryObj.addParam(name="taskId",value=rs_courseChoosers["task_id"][row], cfsqltype="cf_sql_varchar" );
				rs_task = queryObj.execute(sql=sql).getResult();
			
				if ( rs_task.recordCount EQ 0 ) {
					/* 如果根据选课记录 无法倒查教学班 则选课记录是无效记录 */
					arrayAppend( errorTask, [ rs_courseChoosers["task_type"][row],rs_courseChoosers["task_id"][row] ] );
				}
				else {
					switch(rs_courseChoosers["task_type"][row]){
						case 'C':
							sql = "UPDATE 
										t_common_task 
									SET 
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
						case 'P':
							sql = "UPDATE 
										t_task 
									SET 
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
						case 'R':
							sql = "UPDATE 
										t_reopen_task 
									SET 
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
						case 'T':
							sql = "UPDATE 
										t_sport_task 
									SET 
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
					}
		
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskChooesd", value=rs_courseChoosers["countCourse"][row], cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskId", value=rs_courseChoosers["task_id"][row], cfsqltype="cf_sql_varchar" );
					queryObj.execute( sql=sql );
			
				}
				
			}
			
		}
		
		transaction {

			/* 根据 TaskType, TaskID 逆向查询有误选课数据 */
			for ( var error in errorTask ) {
			
				/* 删除学生选课记录 */
				sql = "DELECT t_student_course 
						WHERE task_type = :taskType AND task_id = :taskId ";
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskType", value=error[1], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskId", value=error[2], cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
							
			}
			
		}
		
	}
	
	
	/**
	* @hint "刷新教学任务已选人数"
	* 
	* @event "MachII Event Object"
	*/	
	public void function flushTask( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		var queryObj = "";
		
		var setting = gettagSettingHelper();
		setting.setTimeout(60);

		var termId = event.getArg("TermID", event.getArg("TID"));
		
		var errorTask = [];
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 刷新课程教学班已选人数 */
			sql = "	SELECT
						sc.task_type,sc.task_id,COUNT(*) r_count
					FROM
						t_student_course sc
					WHERE
						sc.term_id = :termId 
					GROUP BY
						sc.task_type,sc.task_id";
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			rs_courseChooser = queryObj.execute(sql = sql).getResult();

			for(a = 1; a lte rs_courseChooser.recordCount; a++){
				
				switch(rs_courseChooser["task_type"][a]){
					case "P":
					
					sql = "	SELECT
								t.tsk_id
							FROM
								t_task t
							WHERE
								t.tsk_id = :taskId ";
					break;	
					
					case "R":
					
					sql = "	SELECT
								t.tsk_id
							FROM
								t_reopen_task t
							WHERE
								t.tsk_id = :taskId ";
					break;	
					
					
					case "C":
					
					sql = "	SELECT
								t.tsk_id
							FROM
								t_common_task t
							WHERE
								t.tsk_id = :taskId ";
					break;	
					
					
					case "T":
					
					sql = "	SELECT
								t.tsk_id
							FROM
								t_sport_task t
							WHERE
								t.tsk_id = :taskId ";
					break;	
				}
				
				queryObj = new Query(datasource = application.dnsMaster);
				queryObj.addParam(name = "taskId", value = rs_courseChooser["task_id"][a], cfsqltype = "cf_sql_varchar");
				rs_taskEntity = queryObj.execute(sql = sql).getResult();

				if(rs_taskEntity.recordCount eq 0){
					/* 如果根据选课记录 无法倒查教学班 则选课记录是无效记录 */
					arrayAppend( errorTask, [ rs_courseChooser["task_type"][a],rs_courseChooser["task_id"][a] ] );
				} else if(rs_taskEntity.recordCount gte 1) {
					switch(rs_courseChooser["task_type"][a]){
						case "P":
						sql = "	UPDATE
									t_task t
								SET
									t.task_chooesd = :realSize 
								WHERE
									t.tsk_id = :taskId ";
						break;
						case "R":
						sql = "	UPDATE
									t_reopen_task t
								SET
									t.task_chooesd = :realSize 
								WHERE
									t.tsk_id = :taskId ";
						break;
						case "C":
						sql = "	UPDATE
									t_common_task t
								SET
									t.task_chooesd = :realSize 
								WHERE
									t.tsk_id = :taskId ";
						break;
						case "T":
						sql = "	UPDATE
									t_sport_task t
								SET
									t.task_chooesd = :realSize 
								WHERE
									t.tsk_id = :taskId ";
						break;
					}

					queryObj = new Query(datasource = application.dnsMaster);
					queryObj.addParam(name = "taskId", value = rs_courseChooser["task_id"][a], cfsqltype = "cf_sql_varchar");
					queryObj.addParam(name = "realSize", value = rs_courseChooser["r_count"][a], cfsqltype = "cf_sql_integer");
					queryObj.execute(sql = sql);
					
				}
			}
		}
		
		transaction {

			/* 根据 TaskType, TaskID 逆向查询有误选课数据 */
			for ( var error in errorTask ) {
			
				/* 删除学生选课记录 */
				sql = "	DELETE FROM
							t_student_course sc
						WHERE
							sc.task_id = :taskId 
							AND
							sc.task_type = :taskType ";
				
				queryObj = new Query(datasource = application.dnsMaster);
				queryObj.addParam(name = "taskId", value = error[2], cfsqltype = "cf_sql_varchar");
				queryObj.addParam(name = "taskType", value = error[1], cfsqltype = "cf_sql_char");
				queryObj.execute(sql = sql);

			}
			
		}

	}
	
	
	/**
	* @hint "更换教学任务教师"
	* 
	* @event "MachII Event Object"
	*/	
	public void function changeTaskTeacher( required MachII.framework.Event event ) output=false {
		
		var sequenceTeacherTimeTable = getsequenceTeacherTimeTable();
		
		var taskId = event.getArg("TaskID");
		var taskType = event.getArg("TaskType");
		
		var passArg = structNew();
		
		var teacherId = event.getArg("TeacherID");
		var teacherIdSecondary = event.getArg("TeacherSecondaryID");
		var teacherIdAssist = event.getArg("TeacherAssistID");
		
		var sql = "";
		var queryObj = "";

		var tchTimeIdx = "";
		var tchTimeId = "";

		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 载入教学任务 */
			switch( taskType ) {
				
				case "P":
					sql = "SELECT 
								a.tch_id, a.tch_id_sec, a.tch_id_ace 
								FROM t_task a 
								WHERE 
									a.tsk_id = :taskId ";
					break;

				case "C":
					sql = "SELECT 
								a.tch_id, a.tch_id_sec, a.tch_id_ace 
								FROM t_common_task a 
								WHERE 
									a.tsk_id = :taskId ";
					break;

				case "R":
					sql = "SELECT 
								a.tch_id, a.tch_id_sec, a.tch_id_ace 
								FROM t_reopen_task a 
								WHERE 
									a.tsk_id = :taskId ";
					break;
				
				case "T":
					sql = "SELECT 
								a.tch_id, a.tch_id_sec, a.tch_id_ace 
								FROM t_sport_task a 
								WHERE 
									a.tsk_id = :taskId ";
					break;
				
			}
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			
			var rs_task = queryObj.execute( sql=sql ).getResult();
			
			/* 如果更换主讲教师 */
			if ( teacherId neq rs_task.tch_id ) { 
				
				/* 读取现有教师时间占用表 */
				sql = "SELECT 
							a.teachertime_id, 
							a.term_id, 
							a.tch_id, 
							a.cid, 
							a.widx, a.wdidx, a.task_week, 
							a.cellidx, a.cellrelay, 
							a.taskclsroom, a.tasktime, 
							a.task_id, a.task_type 
							FROM t_teacher_timetable a
							WHERE 
								a.task_id = :taskId 
								AND 
								a.tch_id = :teacherId ";
							
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="teacherId", value=rs_task.tch_id, cfsqltype="cf_sql_varchar" );
				
				var rs_teacherTimeTable = queryObj.execute( sql=sql ).getResult();
				
				for ( var i=1; i LTE rs_teacherTimeTable.recordCount; i++ ){
					
					sequenceTeacherTimeTable.setTermID( rs_teacherTimeTable["term_id"][i] );
					sequenceTeacherTimeTable.setTeacherID( teacherId );
					
					tchTimeIdx = sequenceTeacherTimeTable.getTimeIDX();
					
					sequenceTeacherTimeTable.setTimeIndex( tchTimeIdx );

					tchTimeId = sequenceTeacherTimeTable.getID();
					
					/* 生成新教师时间占用表 */
					sql = "INSERT INTO t_teacher_timetable 
								(
									teachertime_id,
									tidx,
									term_id, 
									tch_id, 
									cid, 
									widx, 
									wdidx, 
									cellidx, 
									cellrelay, 
									taskclsroom, 
									tasktime, 
									task_id, 
									task_type, 
									task_week 
								) 
								VALUES 
								(
									:teacherTimeId, 
									:timeIndex, 
									:termId, 
									:teacherId, 
									:courseId, 
									:weekIndex, 
									:weekDay, 
									:cellStart, 
									:cellLength, 
									:taskClassRoom, 
									:taskClassTime, 
									:taskId, 
									:taskType, 
									:taskWeek 
								) ";
					
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="teacherTimeId", value=tchTimeId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="timeIndex", value=tchTimeIdx, cfsqltype="cf_sql_char" );
					queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="termId", value=rs_teacherTimeTable["term_id"][i], cfsqltype="cf_sql_char" );
					queryObj.addParam( name="courseId", value=rs_teacherTimeTable["cid"][i], cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="weekIndex", value=rs_teacherTimeTable["widx"][i], cfsqltype="cf_sql_char" );
					queryObj.addParam( name="weekDay", value=rs_teacherTimeTable["wdidx"][i], cfsqltype="cf_sql_char" );
					queryObj.addParam( name="cellStart", value=rs_teacherTimeTable["cellidx"][i], cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="cellLength", value=rs_teacherTimeTable["cellrelay"][i], cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskClassRoom", value=rs_teacherTimeTable["taskclsroom"][i], cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskClassTime", value=rs_teacherTimeTable["tasktime"][i], cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskId", value=rs_teacherTimeTable["task_id"][i], cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskType", value=rs_teacherTimeTable["task_type"][i], cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskWeek", value=rs_teacherTimeTable["task_week"][i], cfsqltype="cf_sql_char" );
					queryObj.execute( sql=sql );
					
					/* 删除原教师时间占用 */
					sql = "DELETE FROM t_teacher_timetable WHERE teachertime_Id = :teacherTimdId ";
					
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="teacherTimdId", value=rs_teacherTimeTable["teachertime_id"][i], cfsqltype="cf_sql_varchar" );
					queryObj.execute( sql=sql );
				}
				
				/* 保存主讲教师 */
				switch(taskType){
					
					case "C":
						sql = "UPDATE t_common_task SET tch_id = :teacherId WHERE tsk_id = :taskId ";
						break;
		
					case "P":
						sql = "UPDATE t_task SET tch_id = :teacherId WHERE tsk_id = :taskId ";
						break;
				
					case "R":
						sql = "UPDATE t_reopen_task SET tch_id = :teacherId WHERE tsk_id = :taskId ";
						break;
				
					case "T":
						sql = "UPDATE t_sport_task SET tch_id = :teacherId WHERE tsk_id = :taskId ";
						break;
				}
				
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );

			}
			
			/* 如果更换第二主讲教师 */
			if ( teacherIdSecondary neq rs_task.tch_id_sec ) {
					
				/* 保存第二主讲教师 */
				switch(taskType){
						
					case "C":
						sql = "UPDATE t_common_task SET tch_id_sec = :teacherId WHERE tsk_id = :taskId ";
						break;
		
					case "P":
						sql = "UPDATE t_task SET tch_id_sec = :teacherId WHERE tsk_id = :taskId ";
						break;
					
					case "R":
						sql = "UPDATE t_reopen_task SET tch_id_sec = :teacherId WHERE tsk_id = :taskId ";
						break;
					
					case "T":
						sql = "UPDATE t_sport_task SET tch_id_sec = :teacherId WHERE tsk_id = :taskId ";
						break;
				}
				
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="teacherId", value=teacherIdSecondary, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
					
			}
				
			/* 如果更换助教 */
			if ( teacherIdAssist neq rs_task.tch_id_ace ) {
					
				/* 保存助教 */
				switch(taskType){
						
					case "C":
						sql = "UPDATE t_common_task SET tch_id_ace = :teacherId WHERE tsk_id = :taskId ";
						break;
			
					case "P":
						sql = "UPDATE t_task SET tch_id_ace = :teacherId WHERE tsk_id = :taskId ";
						break;
						
					case "R":
						sql = "UPDATE t_reopen_task SET tch_id_ace = :teacherId WHERE tsk_id = :taskId ";
						break;
						
					case "T":
						sql = "UPDATE t_sport_task SET tch_id_ace = :teacherId WHERE tsk_id = :taskId ";
						break;
							
				}
					
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="teacherId", value=teacherIdAssist, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
			}
			
			/* 传递原教师代码 */
			structInsert( passArg, "TCH_ID", teacherId );
			event.setArgs( passArg );
		}
		
	}
	
	
	/**
	* @hint "撤销教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function cancelTask( required MachII.framework.Event event ) output=false {

		var sql = "";
		
		var passArg = structNew();
		
		var taskId = event.getArg("TSK");
		var taskType = event.getArg("TT");
		var chooserMode = event.getArg("ProcessStudent");
		var taskReId = event.getArg("TaskIDReSign");
		
		var passArg = structNew();
		
		var taskProp = gettaskPropertyAdvice().init();
		var chooseProp = getchoosePropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 载入教学任务 */
			switch(taskType){
				case "C":
					sql = "SELECT 
								a.task_prop, a.task_chooesd, a.term_id, t_course.institute_id, a.tsk_id 
							FROM 
								t_common_task a 
								INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE 
								a.tsk_id = :taskId ";
					break;
	
				case "P":
					sql = "SELECT 
								a.task_prop, a.task_chooesd, a.term_id, t_course.institute_id, a.tsk_id 
							FROM 
								t_task a 
								INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE 
								a.tsk_id = :taskId ";
					break;
				
				case "R":
					sql = "SELECT 
								a.task_prop, a.task_chooesd, a.term_id, t_course.institute_id, a.tsk_id 
							FROM 
								t_reopen_task a 
								INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE 
								a.tsk_id = :taskId ";
					break;
				
				case "T":
					sql = "SELECT 
								a.task_prop, a.task_chooesd, a.term_id, t_course.institute_id, a.tsk_id 
							FROM 
								t_sport_task a 
								INNER JOIN t_course ON t_course.cid = a.cid 
							WHERE 
								a.tsk_id = :taskId ";
					break;
			}
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			/* 载入排课任务 */
			
	
			/* 删除教学班时间占用情况表 */ 
			
			sql = "DELETE FROM t_task_timetable 
					WHERE task_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
				
			/* 删除地点时间占用表 */
			
			sql = "DELETE FROM t_clsroom_timetable t
					WHERE  t.crtime_id IN(
						SELECT crtime_id FROM t_clsroom_forcourse WHERE task_id = :taskId 
					)";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" ); 
			queryObj.execute( sql=sql );

			/* 删除教师时间占用表 */
			sql = "DELETE FROM t_teacher_timetable  
					WHERE task_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			/* 清除排课时间 地点 */
			taskTime = "";
			taskPlace = "";

			/* 重置教学班最大容量 */
			taskCapacity = 0;

			/* 标注任务属性 */
			taskProp.parseProperty( rs_task.task_prop );
			taskProp.setArrangeDone( false ); /* 是否发布课表 = 否 */
			taskProp.setCancel( true ); /* 是否撤班 = 是 */
			
			taskProps = taskProp.stringProperty();

			/* 清除已排周学时 */
			sql = "UPDATE t_task_arrange   
					SET period_done = 0 
					WHERE task_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
	
			realSize = rs_task.task_chooesd;
		
			/* 处理学生选课记录 */
			switch ( chooserMode ) {
				
				case "1":
					/* 保留选课记录 但解锁选课记录 允许学生撤销 */
					sql = "SELECT choose_prop 
							FROM t_student_course 
							WHERE task_id = :taskId ";
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					rs_taskChooser = queryObj.execute( sql=sql ).getResult();
					
					for(row=1; row LTE rs_taskChooser.recordCount; row++){
						chooseProp.parseProperty( rs_taskChooser["choose_prop"][row] );
						chooseProp.setLocked( false );
						
						sql = "UPDATE t_student_course   
								SET choose_prop = :chooseProp  
								WHERE task_id = :taskId ";
						queryObj = new query( datasource=application.dnsMaster );
						queryObj.addParam( name="chooseProp", value=chooseProp.stringProperty(), cfsqltype="cf_sql_varchar" );
						queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
						queryObj.execute( sql=sql );
					}
					
					break;

				case "2":
					/* 删除选课记录 同时重置任务已选人数 */
					sql = "DELETE FROM t_student_course   
							WHERE task_id = :taskId ";
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.execute( sql=sql );
					
					realSize = 0;

					break;

				case "3":
					/* 载入新教学任务 */
					switch(taskType){
						case "C":
							sql = "SELECT 
										cidx, tsk_id, task_chooesd 
									FROM 
										t_common_task 
									WHERE 
										tsk_id = :taskId ";
							break;
			
						case "P":
							sql = "SELECT 
										cidx, tsk_id, task_chooesd 
									FROM 
										t_task 
									WHERE 
										tsk_id = :taskId ";
							break;
						
						case "R":
							sql = "SELECT 
										cidx, tsk_id, task_chooesd 
									FROM 
										t_reopen_task 
									WHERE 
										tsk_id = :taskId ";
							break;
						
						case "T":
							sql = "SELECT 
										cidx, tsk_id, task_chooesd 
									FROM 
										t_sport_task 
									WHERE 
										tsk_id = :taskId ";
							break;
					}
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskId", value=taskReId, cfsqltype="cf_sql_varchar" );
					rs_taskResign = queryObj.execute( sql=sql ).getResult();
			
					/* 合并到其他教学班 同时重新计算已选人数 */
					
					sql = "UPDATE t_student_course   
							SET cidx = :courseIndex,
								task_id = :taskReId 
							WHERE task_id = :taskId ";
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="courseIndex", value=rs_taskResign.cidx , cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskReId", value=rs_taskResign.tsk_id, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.execute( sql=sql );
				
					switch(taskType){
						case "C":
							sql = "UPDATE  
										t_common_task 
									SET  
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
			
						case "P":
							sql = "UPDATE  
										t_task 
									SET  
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
						
						case "R":
							sql = "UPDATE  
										t_reopen_task 
									SET  
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
						
						case "T":
							sql = "UPDATE  
										t_sport_task 
									SET  
										task_chooesd = :taskChooesd 
									WHERE 
										tsk_id = :taskId ";
							break;
					}
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskChooesd", value=rs_taskResign.task_chooesd + realSize, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskId", value=taskReId, cfsqltype="cf_sql_varchar" );
					queryObj.execute( sql=sql );
					
					realSize = 0;
					
					break;
				
			}
			switch(taskType){
				
				case "C":
					sql = "UPDATE 
								t_common_task 
							SET 
								task_time = :taskTime,
								task_place = :taskPlace,
								task_capacity = :taskCapacity,
								task_prop = :taskProp, 
								task_chooesd = :realSize 
							WHERE 
								tsk_id = :taskId ";
					break;
	
				case "P":
					sql = "UPDATE 
								t_task 
							SET 
								task_time = :taskTime,
								task_place = :taskPlace,
								task_capacity = :taskCapacity,
								task_prop = :taskProp, 
								task_chooesd = :realSize 
							WHERE 
								tsk_id = :taskId ";
					break;
				
				case "R":
					sql = "UPDATE 
								t_reopen_task 
							SET 
								task_time = :taskTime,
								task_place = :taskPlace,
								task_capacity = :taskCapacity,
								task_prop = :taskProp, 
								task_chooesd = :realSize 
							WHERE 
								tsk_id = :taskId ";
					break;
				
				case "T":
					sql = "UPDATE 
								t_sport_task 
							SET 
								task_time = :taskTime,
								task_place = :taskPlace,
								task_capacity = :taskCapacity,
								task_prop = :taskProp, 
								task_chooesd = :realSize 
							WHERE 
								tsk_id = :taskId ";
					break;
			}
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskTime", value=taskTime, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskPlace", value=taskPlace, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskCapacity", value=taskCapacity, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskProp", value=taskProps, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="realSize", value=realSize, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			structInsert(passArg, "TID", rs_task.term_id);
			structInsert(passArg, "DepID", rs_task.institute_id);
			
			/* 生成教学任务修订标注 */
			structInsert(passArg, "TSKED", rs_task.tsk_id);
			
			
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "从教学任务中移除行政班"
	* 
	* @event "MachII Event Object"
	*/	
	public void function removeClassFromPlanTask( required MachII.framework.Event event ) output=false {

		var classNames = "";
		var PlanSize = 0;

		var passArg = structNew();
		var sql = "";

		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT 
						t_task.task_limite, 
						t_task.task_classes, 
						t_task.tsk_id, 
						t_task.cid, 
						t_task.tch_id, 
						t_teacher.tch_name 
					FROM  
						t_task 
						INNER JOIN t_teacher ON t_teacher.tch_id = t_task.tch_id 
					WHERE 
						t_task.tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			PlanSize = rs_task.task_limite;
			classNames = rs_task.task_classes;
			
			structInsert(passArg, "TSK", rs_task.tsk_id);
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			/* 更新班级计划的课序号 */
			
			sql = "SELECT 
						cls_name, cls_size 
					FROM  
						t_class 
					WHERE 
						cls_id = :clsId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="clsId", value=classId, cfsqltype="cf_sql_char" );
			rs_class= queryObj.execute( sql=sql ).getResult();

			classNames = listDeleteAt(classNames, listFind(classNames, rs_class.cls_name));
			PlanSize = PlanSize - rs_class.cls_size;
			
			
			sql = "UPDATE 
						t_plan 
					SET 
						cidx = '000' 
					WHERE 
						cls_id = :clsId  
						AND 
						cid = :courseId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="clsId", value=classId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value=rs_task.cid, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );

			
			/* 更新教学任务的班级列表和计划人数 */
			
			sql = "UPDATE 
						t_task  
					SET 
						task_limite = :taskLimite, 
						task_classes = :taskClasses 
					WHERE 
						tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskLimite", value=PlanSize, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskClasses", value=left(classNames, 100), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );

			
			event.setArgs(passArg);
			
		}
		
	}
	
	
	/**
	* @hint "添加行政班到教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function addClassToPlanTask( required MachII.framework.Event event ) output=false {

		var classId = "";
		var classNames = "";
		var PlanSize = 0;
		
		var passArg = structNew();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT 
						t_task.task_limite, 
						t_task.task_classes, 
						t_task.tsk_id, 
						t_task.cidx, 
						t_task.cid, 
						t_task.tch_id, 
						t_teacher.tch_name 
					FROM  
						t_task 
						INNER JOIN t_teacher ON t_teacher.tch_id = t_task.tch_id 
					WHERE 
						t_task.tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			PlanSize = rs_task.task_limite;
			classNames = rs_task.task_classes;

			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);

			/* 更新班级计划的课序号 */
			for (classId in listToArray(event.getArg("ClassAppendIDs"), ",")) {
				
				sql = "SELECT 
							cls_name, cls_size 
						FROM  
							t_class 
						WHERE 
							cls_id = :clsId ";
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="clsId", value=classId, cfsqltype="cf_sql_char" );
				rs_class= queryObj.execute( sql=sql ).getResult();
			
				classNames = listAppend(classNames, rs_class.cls_name);
				
				PlanSize = PlanSize + rs_class.cls_size;
				
				sql = "UPDATE 
							t_plan 
						SET 
							cidx = :courseIndex  
						WHERE 
							cls_id = :clsId  
							AND 
							cid = :courseId ";
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="courseIndex", value=rs_task.cidx, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="clsId", value=classId, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_task.cid, cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
			}
			
			sql = "UPDATE 
						t_task  
					SET 
						task_limite = :taskLimite, 
						task_classes = :taskClasses 
					WHERE 
						tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskLimite", value=PlanSize, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskClasses", value=left(classNames, 100), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );

			event.setArgs(passArg);
			
		}
		
	}
	
	
	/**
	* @hint "删除教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function removePlanTask( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		
		var passArg = structNew();
		
		var content = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT a.term_id, a.cidx, a.cid, a.tsk_id, b.course_name, a.tch_id   
						FROM t_task a 
							INNER JOIN t_course b ON b.cid = a.cid 
						WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();

			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TSK", rs_task.tsk_id);
			structInsert(passArg, "TT", "P");
			
			content = "删除教学任务安排 " & rs_task.course_name ;
			
			logFactory.stuCourse('12', content, rs_task.tch_id, rs_task.cid, rs_task.term_id);
			
			sql = "UPDATE 
						t_plan 
					SET 
						cidx = '000' 
					WHERE 
						term_id = :termId 
						AND 
						cidx = :courseIndex 
						AND 
						cid = :courseId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=rs_task.term_id, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseIndex", value=rs_task.cidx, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value=rs_task.cid, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			sql = "DELETE FROM t_task WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
	
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "删除通选课教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function removeCommonTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			sql = "SELECT cid 
					FROM t_common_task 
					WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TSK", event.getArg("TaskID"));
			structInsert(passArg, "TT", "C");
			
			var sql = "DELETE FROM t_common_task WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "锁定计划教学任务, 不允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function lockPlanTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(true);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);

			structInsert(passArg, "TSK", rs_task.tsk_id);
			structInsert(passArg, "TT", "P");
			
			sql = "UPDATE t_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
	
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "锁定通选课教学任务, 不允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function lockCommonTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_common_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_common_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(true);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);

			structInsert(passArg, "TSK", rs_task.tsk_id);
			structInsert(passArg, "TT", "C");
			
			sql = "UPDATE t_common_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
	
			event.setArgs(passArg);
			
		}
	}


	/**
	* @hint "解锁制定学期全部计划教学任务, 允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function unlockAllPlanTask( required MachII.framework.Event event ) output=false {
		
		var termId = event.getArg("TID");
		
		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop FROM t_task WHERE term_id = :termId ";

			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			var rs_task = queryObj.execute( sql=sql ).getResult();

			for ( var i=1; i LTE rs_task.recordCount; i++){
				
				propAdvice.parseProperty(rs_task["task_prop"][i]);
				propAdvice.setLocked(false);
				
				sql = "UPDATE t_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskId", value=rs_task["tsk_id"][i], cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
					
			}
			
		}
		
	}

	
	/**
	* @hint "解锁计划教学任务, 允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function unlockPlanTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
		
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(false);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE t_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);
			
		}
	}
	
	/**
	* @hint "解锁通选课教学任务, 允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function unlockCommonTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_common_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_common_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
		
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(false);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE t_common_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "解锁制定学期全部计划教学任务, 允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function unlockAllCommonTask( required MachII.framework.Event event ) output=false {
		
		var termId = event.getArg("TID");
		
		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop FROM t_common_task WHERE term_id = :termId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			var rs_task = queryObj.execute( sql=sql ).getResult();

			for ( var i=1; i LTE rs_task.recordCount; i++){
				
				propAdvice.parseProperty(rs_task["task_prop"][i]);
				propAdvice.setLocked(false);
				
				sql = "UPDATE t_common_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskId", value=rs_task["tsk_id"][i], cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
					
			}
	
		}
		
	}
	
	
	/**
	* @hint "更新教学任务信息"
	* 
	* @event "MachII Event Object"
	*/	
	public void function updatePlanTask( required MachII.framework.Event event ) output=false {
		
		var passArg = structNew();
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var taskLimite = "";
			var taskPeriod = "";
			var taskWeek = "";
			var taskDesc = "";
			var crType = "";
			var campusId = "";
			var tchId = "";
			var weektype = "";
			
			sql = "SELECT 
						t_task.task_limite, 
						t_task.task_period, 
						t_task.task_week, 
						t_task.task_desc, 
						t_task.cr_type, 
						t_task.campus_id, 
						t_teacher.tch_id, 
						t_task.cid, 
						t_teacher.tch_name,
						t_task.week_type  
					FROM  
						t_task 
						INNER JOIN t_teacher ON t_teacher.tch_id = t_task.tch_id 
					WHERE 
						tsk_id = :taskId  ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();

			if (event.isArgDefined("PlanSize")) { 
				taskLimite = event.getArg("PlanSize");
			}else{
				taskLimite = rs_task.task_limite;
			}
			if (event.isArgDefined("TaskPeriod")) { 
				taskPeriod = event.getArg("TaskPeriod");
			}else{
				taskPeriod = rs_task.task_period;
			}
			if (event.isArgDefined("WeekStart") and event.isArgDefined("WeekEnd")) { 
				taskWeek = numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_");
			}else{
				taskWeek = rs_task.task_week;
			}
			if (event.isArgDefined("Describe")) { 
				taskDesc = event.getArg("Describe");
			}else{
				taskDesc = rs_task.task_desc;
			}

			if (event.isArgDefined("ClassroomType")) {
				crType = event.getArg("ClassroomType");
			}else{
				crType = rs_task.cr_type;
			}
			
			if (event.isArgDefined("CampusID")) {
				campusId = event.getArg("CampusID");
			}else{
				campusId = rs_task.campus_id;
			}
			
			if (event.isArgDefined("TeacherID")) {
				tchId = event.getArg("TeacherID");
			}else{
				tchId = rs_task.tch_id;
			}
			
			if (event.isArgDefined("weekType")) {
				weekType = event.getArg("weekType");
			}else{
				weekType = rs_task.week_type;
			}

			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE 
						t_task 
					SET 
						task_limite = :taskLimite, 
						task_period = :taskPeriod, 
						task_week = :taskWeek, 
						task_desc = :taskDesc, 
						cr_type = :crType, 
						campus_id = :campusId, 
						tch_id = :tchId,
						week_type = :weekType  
					WHERE 
						tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskLimite", value=taskLimite, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskPeriod", value=taskPeriod, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskDesc", value=taskDesc, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="crType", value=crType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="campusId", value=campusId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="tchId", value=tchId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="weekType", value=weekType, cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);

		}
	}
	
	
	/**
	* @hint "更新通选课教学任务信息"
	* 
	* @event "MachII Event Object"
	*/	
	public void function updateCommonTask( required MachII.framework.Event event ) output=false {
		
	
		var passArg = structNew();
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			var taskLimite = "";
			var taskPeriod = "";
			var taskWeek = "";
			var taskDesc = "";
			var crType = "";
			var campusId = "";
			var tchId = "";
			
			sql = "SELECT 
						t_common_task.task_limite, 
						t_common_task.task_period, 
						t_common_task.task_week, 
						t_common_task.task_desc, 
						t_common_task.cr_type, 
						t_common_task.campus_id, 
						t_teacher.tch_id, 
						t_common_task.cid, 
						t_teacher.tch_name 
					FROM  
						t_common_task
						INNER JOIN t_teacher ON t_teacher.tch_id = t_common_task.tch_id 
					WHERE 
						t_common_task.tsk_id = :taskId  ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
		
			if (event.isArgDefined("PlanSize")) { 
				taskLimite = event.getArg("PlanSize");
			}else{
				taskLimite = rs_task.task_limite;
			}
			
			if (event.isArgDefined("TaskPeriod")) { 
				taskPeriod = event.getArg("TaskPeriod");
			}else{
				taskPeriod = rs_task.task_period;
			}
			
			if (event.isArgDefined("WeekStart") and event.isArgDefined("WeekEnd")) { 
				taskWeek = numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_");
			}else{
				taskWeek = rs_task.task_week;
			}	
					
			if (event.isArgDefined("Describe")) { 
				taskDesc = event.getArg("Describe");
			}else{
				taskDesc = rs_task.task_desc;
			}

			if (event.isArgDefined("ClassroomType")) {
				crType = event.getArg("ClassroomType");
			}else{
				crType = rs_task.cr_type;
			}
			
			if (event.isArgDefined("CampusID")) {
				campusId = event.getArg("CampusID");
			}else{
				campusId = rs_task.campus_id;
			}
			
			if (event.isArgDefined("TeacherID")) {
				tchId = event.getArg("TeacherID");
			}else{
				tchId = rs_task.tch_id;
			}
			
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE 
						t_common_task 
					SET 
						task_limite = :taskLimite, 
						task_period = :taskPeriod, 
						task_week = :taskWeek, 
						task_desc = :taskDesc, 
						cr_type = :crType, 
						campus_id = :campusId, 
						tch_id = :tchId 
					WHERE 
						tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskLimite", value=taskLimite, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskPeriod", value=taskPeriod, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskDesc", value=taskDesc, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="crType", value=crType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="campusId", value=campusId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="tchId", value=tchId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);

		}
	}
	
	
	/**
	* @hint "创建课程教学任务及合班信息"
	* 
	* @event "MachII Event Object"
	*/	
	public void function createPlanTask( required MachII.framework.Event event ) output=false {
		
		var sequenceProgramTask = getsequenceProgramTask();
		
		var courseIDX = "";

		var classId = "";
		var classNames = "";
		
		var taskId = "";
		
		var passArg = structNew();
		
		var propAdvice = gettaskPropertyAdvice().init();
		
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
		
			sql = "SELECT tch_name 
					  FROM t_teacher 
					  WHERE tch_id = :tchId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			rs_teacher = queryObj.execute( sql=sql ).getResult();
			
			structInsert(passArg, "CID", event.getArg("CourseID"));
			structInsert(passArg, "TCHID", event.getArg("TeacherID"));
			structInsert(passArg, "TNAME", rs_teacher.tch_name);
												
			/* 生成课序号 */
			sequenceProgramTask.setTermID(event.getArg("TermID"));
			sequenceProgramTask.setCourseID(event.getArg("CourseID"));
			courseIDX = sequenceProgramTask.getIDX();
			sequenceProgramTask.setCourseIndex(courseIDX);

			/* 生成教学班号 */
			taskId = sequenceProgramTask.getID();

			
			/* 更新班级计划的课序号 */
			for (classId in listToArray(event.getArg("ClassIDs"), ",")) {
				
				sql = "SELECT cls_name  
							FROM t_class  
							WHERE cls_id = :clsId ";
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="clsId", value=classId, cfsqltype="cf_sql_char" );
				rs_class = queryObj.execute( sql=sql ).getResult();

				classNames = listAppend(classNames, rs_class.cls_name);
				
				sql = "UPDATE 
								t_plan 
							SET 
								cidx = :courseIndex 
							WHERE 
								cls_id = :clsId 
								AND 
								cid = :courseId ";
				queryObj = new query( datasource=application.dnsMaster );
				queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="clsId", value=classId, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );

			}
	
			sql = "INSERT INTO 
					   t_task( 
							   task_week, 
							   task_period, 
							   task_capacity, 
							   task_limite, 
							   task_chooesd, 
							   task_desc, 
							   task_mode, 
							   term_id, 
							   cid, 
							   tch_id, 
							   tch_id_sec, 
							   tch_id_ace, 
							   campus_id, 
							   cr_type, 
							   task_prop, 
							   tsk_id, 
							   cidx, 
							   task_classes,
							   week_type  
						  )VALUES(
							   :taskWeek, 
							   :taskPeriod, 
							   :taskCapacity, 
							   :taskLimite, 
							   :taskChooesd, 
							   :taskDesc, 
							   :taskMode, 
							   :termId, 
							   :courseId, 
							   :tchId, 
							   :tchIdSec, 
							   :tchIdAce, 
							   :campusId, 
							   :crType, 
							   :taskProp, 
							   :taskId, 
							   :courseIndex, 
							   :taskClasses,
							   :weekType  
						 )";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskPeriod", value=event.getArg("TaskPeriod"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskMode", value="1", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="campusId", value='01', cfsqltype="cf_sql_char" );
			queryObj.addParam( name="crType", value=event.getArg("ClassroomType"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskClasses", value=left(classNames, 100), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="weekType", value=event.getArg("weekType"), cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
	
			event.setArgs(passArg);
			
		}
		
	}
	
	
	/**
	* @hint "创建课程教学任务及合班信息 - 特殊教学任务（实习、学士学位论文）"
	* 
	* @event "MachII Event Object"
	*/	
	public void function createPlanTaskSpecial( required MachII.framework.Event event ) output=false {
		
		var sequenceProgramTask = getsequenceProgramTask();
		
		var courseIDX = "";
		
		var taskId = "";
		
		var passArg = structNew();
		
		var propAdvice = gettaskPropertyAdvice().init();
		
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
		
			sql = "SELECT tch_name 
					  FROM t_teacher 
					  WHERE tch_id = :tchId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			rs_teacher = queryObj.execute( sql=sql ).getResult();
			
			structInsert(passArg, "CID", event.getArg("CourseID"));
			//structInsert(passArg, "TCHID", event.getArg("TeacherID"));
			//structInsert(passArg, "TNAME", rs_teacher.tch_name);
												
			/* 生成课序号 */
			sequenceProgramTask.setTermID(event.getArg("TermID"));
			sequenceProgramTask.setCourseID(event.getArg("CourseID"));
			courseIDX = sequenceProgramTask.getIDX();
			sequenceProgramTask.setCourseIndex(courseIDX);

			/* 生成教学班号 */
			taskId = sequenceProgramTask.getID();

		
	
			sql = "INSERT INTO 
					   t_task( 
							   task_week, 
							   task_period, 
							   task_capacity, 
							   task_limite, 
							   task_chooesd, 
							   task_desc, 
							   task_mode, 
							   term_id, 
							   cid, 
							   tch_id, 
							   tch_id_sec, 
							   tch_id_ace, 
							   campus_id, 
							   cr_type, 
							   task_prop, 
							   tsk_id, 
							   cidx, 
							   task_classes,
							   week_type  
						  )VALUES(
							   :taskWeek, 
							   :taskPeriod, 
							   :taskCapacity, 
							   :taskLimite, 
							   :taskChooesd, 
							   :taskDesc, 
							   :taskMode, 
							   :termId, 
							   :courseId, 
							   :tchId, 
							   :tchIdSec, 
							   :tchIdAce, 
							   :campusId, 
							   :crType, 
							   :taskProp, 
							   :taskId, 
							   :courseIndex, 
							   :taskClasses,
							   :weekType  
						 )";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskPeriod", value="", cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskMode", value="1", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="campusId", value='01', cfsqltype="cf_sql_char" );
			queryObj.addParam( name="crType", value="", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskClasses", value="", cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="weekType", value="0", cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
	
			event.setArgs(passArg);
			
		}
		
	}
	
	
	/**
	* @hint "创建通选课教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function createCommonTask( required MachII.framework.Event event ) output=false {
		
		var sequenceCommonTask = getsequenceCommonTask();
		
		var courseIDX = "";
		var sql = "";
		
		var taskId = "";
		var taskCount = event.getArg("TaskCount", 1);
		
		var i = 1;
		
		var passArg = structNew();
		
		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT tch_name 
					  FROM t_teacher 
					  WHERE tch_id = :tchId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			rs_teacher = queryObj.execute( sql=sql ).getResult();
	
			structInsert(passArg, "CID", event.getArg("CourseID"));
			structInsert(passArg, "TCHID", event.getArg("TeacherID"));
			structInsert(passArg, "TNAME", rs_teacher.tch_name);
					
			/* 生成课序号 */
			sequenceCommonTask.setTermID(event.getArg("TermID"));
			sequenceCommonTask.setCourseID(event.getArg("CourseID"));
			courseIDX = sequenceCommonTask.getIDX();

			/* 生成教学班号 */
			sequenceCommonTask.setcourseIDX(courseIDX);
			taskId = sequenceCommonTask.getID();

			sql = "INSERT INTO 
					   t_common_task( 
							   task_week, 
							   task_period, 
							   task_capacity, 
							   task_limite, 
							   task_chooesd, 
							   task_desc, 
							   task_mode, 
							   term_id, 
							   cid, 
							   tch_id, 
							   tch_id_sec, 
							   tch_id_ace, 
							   campus_id, 
							   cr_type, 
							   task_prop, 
							   tsk_id, 
							   cidx 
						  )VALUES(
							   :taskWeek, 
							   :taskPeriod, 
							   :taskCapacity, 
							   :taskLimite, 
							   :taskChooesd, 
							   :taskDesc, 
							   :taskMode, 
							   :termId, 
							   :courseId, 
							   :tchId, 
							   :tchIdSec, 
							   :tchIdAce, 
							   :campusId, 
							   :crType, 
							   :taskProp, 
							   :taskId, 
							   :courseIndex 
						 )";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskPeriod", value=event.getArg("TaskPeriod"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskMode", value="2", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="campusId", value=event.getArg("CampusID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="crType", value=event.getArg("ClassroomType"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
			
			/* 批量创建教学任务 */
			if (taskCount gt 1) {
				for (i=2; i lte taskCount; i++) {
					
					/* 追加新的课序号 */
					courseIDX = left(courseIDX, 1) & numberFormat((right(courseIDX,2) + 1), "0_");
					/* 生成教学班号 */
					sequenceCommonTask.setcourseIDX(courseIDX);
					taskId = sequenceCommonTask.getID();
					
					
					sql = "INSERT INTO 
							   t_common_task( 
									   task_week, 
									   task_period, 
									   task_capacity, 
									   task_limite, 
									   task_chooesd, 
									   task_desc, 
									   task_mode, 
									   term_id, 
									   cid, 
									   tch_id, 
									   tch_id_sec, 
									   tch_id_ace, 
									   campus_id, 
									   cr_type, 
									   task_prop, 
									   tsk_id, 
									   cidx 
								  )VALUES(
									   :taskWeek, 
									   :taskPeriod, 
									   :taskCapacity, 
									   :taskLimite, 
									   :taskChooesd, 
									   :taskDesc, 
									   :taskMode, 
									   :termId, 
									   :courseId, 
									   :tchId, 
									   :tchIdSec, 
									   :tchIdAce, 
									   :campusId, 
									   :crType, 
									   :taskProp, 
									   :taskId, 
									   :courseIndex 
								 )";
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskPeriod", value=event.getArg("TaskPeriod"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskMode", value="2", cfsqltype="cf_sql_char" );
					queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="campusId", value=event.getArg("CampusID"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="crType", value=event.getArg("ClassroomType"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
					queryObj.execute( sql=sql );
					
				}
			}
			
			event.setArgs(passArg);
		}
		
	}
	
	/**
	* @hint "创建体育项目教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function createSportTask( required MachII.framework.Event event ) output=false {
		
		var sequenceSportTask = getsequenceSportTask();
		
		var courseIDX = "";
		var sql = "";
		
		var i = 1;
		
		var passArg = structNew();
		
		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT tch_name 
					  FROM t_teacher 
					  WHERE tch_id = :tchId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			rs_teacher = queryObj.execute( sql=sql ).getResult();
			
			taskType=event.getArg("TaskType");
			
			structInsert(passArg, "CID", event.getArg("CourseID"));
			structInsert(passArg, "TCHID", event.getArg("TeacherID"));
			structInsert(passArg, "TNAME", rs_teacher.tch_name);
			
			/* 生成课序号 */
			sequenceSportTask.setTermID(event.getArg("TermID"));
			sequenceSportTask.setCourseID(event.getArg("CourseID"));
			courseIDX = sequenceSportTask.getCourseIDX();
			
			/* 生成教学班号 */
			sequenceSportTask.setCourseIndex(courseIDX);
			taskId = sequenceSportTask.getID();
			
			sql = "INSERT INTO 
					   t_sport_task( 
							   task_week, 
							   task_period, 
							   task_capacity, 
							   task_limite, 
							   task_chooesd, 
							   task_desc, 
							   task_mode, 
							   term_id, 
							   cid, 
							   tch_id, 
							   tch_id_sec, 
							   tch_id_ace, 
							   campus_id, 
							   cr_type, 
							   task_prop, 
							   tsk_id, 
							   cidx 
						  )VALUES(
							   :taskWeek, 
							   :taskPeriod, 
							   :taskCapacity, 
							   :taskLimite, 
							   :taskChooesd, 
							   :taskDesc, 
							   :taskMode, 
							   :termId, 
							   :courseId, 
							   :tchId, 
							   :tchIdSec, 
							   :tchIdAce, 
							   :campusId, 
							   :crType, 
							   :taskProp, 
							   :taskId, 
							   :courseIndex 
						 )";
						 
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskPeriod", value=event.getArg("TaskPeriod"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskMode", value="2", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="campusId", value=event.getArg("CampusID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="crType", value=event.getArg("ClassroomType"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );
			
			/* 批量创建教学任务 */
			if (taskCount gt 1) {
				for (i=2; i lte taskCount; i++) {
					
					/* 追加新的课序号 */
					courseIDX = left(courseIDX, 1) & numberFormat((right(courseIDX,2) + 1), "0_");
					/* 生成教学班号 */
					sequenceSportTask.setCourseIndex(courseIDX);
					taskId = sequenceSportTask.getID();
										
					sql = "INSERT INTO 
							   t_sport_task( 
									   task_week, 
									   task_period, 
									   task_capacity, 
									   task_limite, 
									   task_chooesd, 
									   task_desc, 
									   task_mode, 
									   term_id, 
									   cid, 
									   tch_id, 
									   tch_id_sec, 
									   tch_id_ace, 
									   campus_id, 
									   cr_type, 
									   task_prop, 
									   tsk_id, 
									   cidx 
								  )VALUES(
									   :taskWeek, 
									   :taskPeriod, 
									   :taskCapacity, 
									   :taskLimite, 
									   :taskChooesd, 
									   :taskDesc, 
									   :taskMode, 
									   :termId, 
									   :courseId, 
									   :tchId, 
									   :tchIdSec, 
									   :tchIdAce, 
									   :campusId, 
									   :crType, 
									   :taskProp, 
									   :taskId, 
									   :courseIndex 
								 )";
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskPeriod", value=event.getArg("TaskPeriod"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskMode", value="2", cfsqltype="cf_sql_char" );
					queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="campusId", value=event.getArg("CampusID"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="crType", value=event.getArg("ClassroomType"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
					queryObj.execute( sql=sql );
					
				}
			}
			
			event.setArgs(passArg);
		}
		
	}
	
	
	/**
	* @hint "更新体育项目教学任务信息"
	* 
	* @event "MachII Event Object"
	*/	
	public void function updateSportTask( required MachII.framework.Event event ) output=false {
		
		var passArg = structNew();
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			var taskLimite = "";
			var taskPeriod = "";
			var taskWeek = "";
			var taskDesc = "";
			var crType = "";
			var campusId = "";
			var tchId = "";
			
			
			sql = "SELECT 
						t_sport_task.task_limite, 
						t_sport_task.task_period, 
						t_sport_task.task_week, 
						t_sport_task.task_desc, 
						t_sport_task.cr_type, 
						t_sport_task.campus_id, 
						t_teacher.tch_id, 
						t_sport_task.cid, 
						t_teacher.tch_name 
					FROM  
						t_sport_task 
						INNER JOIN t_teacher ON t_teacher.tch_id = t_sport_task.tch_id 
					WHERE 
						t_sport_task.tsk_id = :taskId  ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
		
			if (event.isArgDefined("PlanSize")) { 
				taskLimite = event.getArg("PlanSize");
			}else{
				taskLimite = rs_task.task_limite;
			}
			
			if (event.isArgDefined("TaskPeriod")) { 
				taskPeriod = event.getArg("TaskPeriod");
			}else{
				taskPeriod = rs_task.task_period;
			}
			
			if (event.isArgDefined("WeekStart") and event.isArgDefined("WeekEnd")) { 
				taskWeek = numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_");
			}else{
				taskWeek = rs_task.task_week;
			}	
			
			if (event.isArgDefined("Describe")) { 
				taskDesc = event.getArg("Describe");
			}else{
				taskDesc = rs_task.task_desc;
			}
			
			if (event.isArgDefined("ClassroomType")) {
				crType = event.getArg("ClassroomType");
			}else{
				crType = rs_task.cr_type;
			}
		
			if (event.isArgDefined("CampusID")) {
				campusId = event.getArg("CampusID");
			}else{
				campusId = rs_task.campus_id;
			}			
			
			if (event.isArgDefined("TeacherID")) {
				tchId = event.getArg("TeacherID");
			}else{
				tchId = rs_task.tch_id;
			}
	
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE 
						t_sport_task 
					SET 
						task_limite = :taskLimite, 
						task_period = :taskPeriod, 
						task_week = :taskWeek, 
						task_desc = :taskDesc, 
						cr_type = :crType, 
						campus_id = :campusId, 
						tch_id = :tchId 
					WHERE 
						tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskLimite", value=taskLimite, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskPeriod", value=taskPeriod, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskDesc", value=taskDesc, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="crType", value=crType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="campusId", value=campusId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="tchId", value=tchId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
		
			event.setArgs(passArg);

		}
	}

	
	/**
	* @hint "删除体育项目教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function removeSportTask( required MachII.framework.Event event ) output=false {
		
		var task = "";
	
		var passArg = structNew();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT cid FROM t_sport_task WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TSK", event.getArg("TaskID"));
			structInsert(passArg, "TT", "C");   
			
			var sql = "DELETE FROM t_sport_task WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "解锁体育项目教学任务, 允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function unlockSportTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_sport_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_sport_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
		
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(false);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE t_sport_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);
					
		}
	}
	
	
	/**
	* @hint "锁定通选课教学任务, 不允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function lockSportTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_sport_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_sport_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(true);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);

			structInsert(passArg, "TSK", rs_task.tsk_id);
			structInsert(passArg, "TT", "T");
			
			sql = "UPDATE t_sport_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
	
			event.setArgs(passArg);
		
		}
	}
	
	
	/**
	* @hint "创建特殊课程教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function createOpenTask( required MachII.framework.Event event ) output=false {
		
		var sequenceOpenTask = getsequenceOpenTask();
		
		var courseIDX = "";

		var sql = "";

		var taskId = "";
		var taskCount = event.getArg("TaskCount", 1);
		
		var i = 1;
		
		var passArg = structNew();
		
		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
				
			sql = "SELECT tch_name 
					  FROM t_teacher 
					  WHERE tch_id = :tchId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			rs_teacher = queryObj.execute( sql=sql ).getResult();
	
			taskType=event.getArg("TaskType");
			
			structInsert(passArg, "CID", event.getArg("CourseID"));
			structInsert(passArg, "TCHID", event.getArg("TeacherID"));
			structInsert(passArg, "TNAME", rs_teacher.tch_name);
			
			/* 生成课序号 */
			sequenceOpenTask.setTermID(event.getArg("TermID"));
			sequenceOpenTask.setCourseID(event.getArg("CourseID"));
			sequenceOpenTask.setTypeId(taskType);
			courseIDX = sequenceOpenTask.getIDX();

			/* 生成教学班号 */
			sequenceOpenTask.setcourseIDX(courseIDX);
			taskId = sequenceOpenTask.getID();
			
			sql = "INSERT INTO 
					   t_reopen_task( 
							   task_week, 
							   task_period, 
							   task_capacity, 
							   task_limite, 
							   task_chooesd, 
							   task_desc, 
							   task_mode, 
							   term_id, 
							   cid, 
							   tch_id, 
							   tch_id_sec, 
							   tch_id_ace, 
							   campus_id, 
							   cr_type, 
							   task_prop, 
							   tsk_id, 
							   cidx 
						  )VALUES(
							   :taskWeek, 
							   :taskPeriod, 
							   :taskCapacity, 
							   :taskLimite, 
							   :taskChooesd, 
							   :taskDesc, 
							   :taskMode, 
							   :termId, 
							   :courseId, 
							   :tchId, 
							   :tchIdSec, 
							   :tchIdAce, 
							   :campusId, 
							   :crType, 
							   :taskProp, 
							   :taskId, 
							   :courseIndex 
						 )";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskPeriod", value=event.getArg("TaskPeriod"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskMode", value="2", cfsqltype="cf_sql_char" );
			queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="campusId", value=event.getArg("CampusID"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="crType", value=event.getArg("ClassroomType"), cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
		
			
			/* 批量创建教学任务 */
			if (taskCount gt 1) {
				for (i=2; i lte taskCount; i++) {
					/* 追加新的课序号 */
					courseIDX = left(courseIDX, 1) & numberFormat((right(courseIDX,2) + 1), "0_");
					/* 生成教学班号 */
					sequenceOpenTask.setcourseIDX(courseIDX);
					taskId = sequenceOpenTask.getID();
					
					sql = "INSERT INTO 
							   t_reopen_task( 
									   task_week, 
									   task_period, 
									   task_capacity, 
									   task_limite, 
									   task_chooesd, 
									   task_desc, 
									   task_mode, 
									   term_id, 
									   cid, 
									   tch_id, 
									   tch_id_sec, 
									   tch_id_ace, 
									   campus_id, 
									   cr_type, 
									   task_prop, 
									   tsk_id, 
									   cidx 
								  )VALUES(
									   :taskWeek, 
									   :taskPeriod, 
									   :taskCapacity, 
									   :taskLimite, 
									   :taskChooesd, 
									   :taskDesc, 
									   :taskMode, 
									   :termId, 
									   :courseId, 
									   :tchId, 
									   :tchIdSec, 
									   :tchIdAce, 
									   :campusId, 
									   :crType, 
									   :taskProp, 
									   :taskId, 
									   :courseIndex 
								 )";
					queryObj = new query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskWeek", value=numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskPeriod", value=event.getArg("TaskPeriod"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskCapacity", value=0, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskLimite", value=event.getArg("PlanSize"), cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskChooesd", value=0, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="taskDesc", value=event.getArg("Describe"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskMode", value="2", cfsqltype="cf_sql_char" );
					queryObj.addParam( name="termId", value=event.getArg("TermID"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="courseId", value= event.getArg("CourseID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchId", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchIdSec", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="tchIdAce", value=event.getArg("TeacherID"), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="campusId", value=event.getArg("CampusID"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="crType", value=event.getArg("ClassroomType"), cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="courseIndex", value=courseIDX, cfsqltype="cf_sql_char" );
					queryObj.execute( sql=sql );

				}
			}
			
			event.setArgs(passArg);
		}
		
	}
	
	
	/**
	* @hint "更新特殊课程教学任务信息"
	* 
	* @event "MachII Event Object"
	*/	
	public void function updateOpenTask( required MachII.framework.Event event ) output=false {
		
		var passArg = structNew();
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			var taskLimite = "";
			var taskPeriod = "";
			var taskWeek = "";
			var taskDesc = "";
			var crType = "";
			var campusId = "";
			var tchId = "";
			
			sql = "SELECT 
						t_reopen_task.task_limite, 
						t_reopen_task.task_period, 
						t_reopen_task.task_week, 
						t_reopen_task.task_desc, 
						t_reopen_task.cr_type, 
						t_reopen_task.campus_id, 
						t_teacher.tch_id, 
						t_reopen_task.cid, 
						t_teacher.tch_name 
					FROM  
						t_reopen_task
						INNER JOIN t_teacher ON t_teacher.tch_id = t_reopen_task.tch_id 
					WHERE 
						t_reopen_task.tsk_id = :taskId  ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			if (event.isArgDefined("PlanSize")) { 
				taskLimite = event.getArg("PlanSize");
			}else{
				taskLimite = rs_task.task_limite;
			}
			if (event.isArgDefined("TaskPeriod")) { 
				taskPeriod = event.getArg("TaskPeriod");
			}else{
				taskPeriod = rs_task.task_period;
			}
			if (event.isArgDefined("WeekStart") and event.isArgDefined("WeekEnd")) { 
				taskWeek = numberFormat(event.getArg("WeekStart"), "0_") & "-" & numberFormat(event.getArg("WeekEnd"), "0_");
			}else{
				taskWeek = rs_task.task_week;
			}	
			if (event.isArgDefined("Describe")) { 
				taskDesc = event.getArg("Describe");
			}else{
				taskDesc = rs_task.task_desc;
			}

			if (event.isArgDefined("ClassroomType")) {
				crType = event.getArg("ClassroomType");
			}else{
				crType = rs_task.cr_type;
			}
			
			if (event.isArgDefined("CampusID")) {
				campusId = event.getArg("CampusID");
			}else{
				campusId = rs_task.campus_id;
			}			
			
			if (event.isArgDefined("TeacherID")) {
				tchId = event.getArg("TeacherID");
			}else{
				tchId = rs_task.tch_id;
			}
			
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE 
						t_reopen_task 
					SET 
						task_limite = :taskLimite, 
						task_period = :taskPeriod, 
						task_week = :taskWeek, 
						task_desc = :taskDesc, 
						cr_type = :crType, 
						campus_id = :campusId, 
						tch_id = :tchId 
					WHERE 
						tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskLimite", value=taskLimite, cfsqltype="cf_sql_integer" );
			queryObj.addParam( name="taskPeriod", value=taskPeriod, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskWeek", value=taskWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskDesc", value=taskDesc, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="crType", value=crType, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="campusId", value=campusId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="tchId", value=tchId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);

		}
	}
	
	
	/**
	* @hint "解锁特殊课程教学任务, 允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function unlockOpenTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_reopen_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_reopen_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
		
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(false);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);
			
			sql = "UPDATE t_reopen_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "锁定特殊课程教学任务, 不允许修改任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function lockOpenTask( required MachII.framework.Event event ) output=false {

		var task = "";
		
		var passArg = structNew();

		var propAdvice = gettaskPropertyAdvice().init();

		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			var sql = "SELECT tsk_id, task_prop, cid, t_teacher.tch_id, t_teacher.tch_name 
						 FROM t_reopen_task 
							  INNER JOIN t_teacher ON t_teacher.tch_id = t_reopen_task.tch_id  	
						 WHERE tsk_id = :taskId ";
			var queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute( sql=sql ).getResult();
			
			propAdvice.parseProperty(rs_task.task_prop);
			propAdvice.setLocked(true);
		
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TCHID", rs_task.tch_id);
			structInsert(passArg, "TNAME", rs_task.tch_name);

			structInsert(passArg, "TSK", rs_task.tsk_id);
			structInsert(passArg, "TT", "R");
			
			sql = "UPDATE t_reopen_task SET task_prop = :taskProp WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="taskId", value=rs_task.tsk_id, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
	
			event.setArgs(passArg);
			
		}
	}
	
	
	/**
	* @hint "删除特殊课程教学任务"
	* 
	* @event "MachII Event Object"
	*/	
	public void function removeOpenTask( required MachII.framework.Event event ) output=false {

		var passArg = structNew();
		var sql = "";
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			sql = "SELECT cid 
					FROM t_reopen_task 
					WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			structInsert(passArg, "CID", rs_task.cid);
			structInsert(passArg, "TSK", event.getArg("TaskID"));
			structInsert(passArg, "TT", "R");
			
			var sql = "DELETE FROM t_reopen_task WHERE tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			event.setArgs(passArg);
			
		}
	}
	
	
	

}
	
</cfscript>